<?php defined('IN_IA') or exit('Access Denied');?><?php  include $this->template(wl_header, TEMPLATE_INCLUDEPATH);?>
<link href='<?php echo RES;?>css/member.css' rel='stylesheet' type='text/css' />
<link type="text/css" rel="stylesheet" href="./resource/style/font-awesome.min.css" />
<script type="text/javascript" src="<?php echo RES;?>js/wei_webapp_v2_common.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RES;?>css/wei_dialog.css" media="all" />
<link rel="stylesheet" type="text/css" href="<?php echo RES;?>css/homefeast.css" media="all" />

<div id="shop_page_contents"  style="margin-bottom:25px;">
	<?php  include $this->template(wl_menu, TEMPLATE_INCLUDEPATH);?>
        <div class="all_content">
		<p></p>
	</div>
	<div class="manage_title">
		<p>订单管理</p>
	</div>
	<img class="card" src="<?php echo RESNEW;?>images/content.jpg" />
	<div class="manage_name">
		<p>尊敬的：邓芝蛟</p>
	</div>
 	<div class="manage_State">
    <a name='ser'></a>
    <?php  if($ischef==1) { ?>
		<p <?php  if($_GPC['sendstatus']==0) { ?>class="cur"<?php  } ?>><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','sendstatus'=>0,'ischef'=>1));?>">待服务</a></p>
		<p <?php  if($_GPC['sendstatus']==1) { ?>class="cur"<?php  } ?>><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','sendstatus'=>1,'ischef'=>1));?>">服务中</a></p>

		<p <?php  if($_GPC['sendstatus']==3) { ?>class="cur"<?php  } ?>><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','sendstatus'=>4,'ischef'=>1));?>">已完成</a></p>
   <?php  } else { ?>
		<p  class="State1"><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','status'=>0));?>#ser" style="color:#c39b60;">未付定金</a></p>
		<p class="State"><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','status'=>1));?>#ser" style="color:#c39b60;">已付款</a></p>
		<p  class="State"><a href="<?php  echo $this->createMobileUrl('wlmember',array('d'=>'list','status'=>4));?>#ser" style="color:#c39b60;">历史订单</a></p>
   <?php  } ?>
   		
	</div>
	<?php  if($_GPC['d']=='list'||empty($_GPC['d'])) { ?>
	<div id="order_list">
		<?php  if(is_array($list)) { foreach($list as $row) { ?>
		<div class="cont_porsonal2">
			<img src="<?php echo RESNEW;?>images/contentlogo.jpg" />
			<div class="porsonal_infor1">
				<p>订 单 号：<span><?php  echo $row['ordersn'];?></span></p>
				<p>订单实效：23小时59分后订单自动取消</p>
				<p>预约时间：<?php  echo $row['time_day'];?></p>
				<p>订单金额：￥500.00  总金额：￥<?php  echo number_format($row['totalprice'],2)?></p>
			</div>
			<div class="rightop">
				<p>待</p>	
			</div>
	          </div>
		<?php  } } ?>
        <div style="text-align: center;">
		<?php  echo $pager;?>
        </div>
	</div>
	<?php  } ?>
	<?php  if($_GPC['d']=='detail') { ?>	
	<div id="order_detail">
			<div class="item">
            <?php  if($order['status']==2) { ?>
                <?php  if($fansinfo["grade"]<>1 ) { ?>
            <ul><li style="text-align: center;"><img src="./mobile.php?act=module&d=detail&name=shopping3&do=wlqrcode&weid=<?php  echo $weid;?>&orderid=<?php  echo $orderid;?>" width="150" height="150" /></li></ul>
                <?php  } else { ?>
                   <?php  if($order['from_user']==$fansinfo["from_user"] ) { ?>
                   
            <ul><li style="text-align: center;"><img src="./mobile.php?act=module&d=detail&name=shopping3&do=wlqrcode&weid=<?php  echo $weid;?>&orderid=<?php  echo $orderid;?>" width="150" height="150" /></li></ul>
                   
                   <?php  } ?>
                
                <?php  } ?>
            <?php  } ?>

			<ul>
				<li>订单号：<?php  echo $order['ordersn'];?></li>
				<li>订单时间: <?php  echo date('Y-m-d H:i:s',$order['createtime'])?></li>
				<li>订单状态: <?php  if($order['status']==0) { ?>待确认<?php  } else if($order['status']==1) { ?>已确认<?php  } else if($order['status']==2) { ?>已付款<?php  } else if($order['status']==3) { ?>已完成<?php  } else if($order['status']==-1) { ?>订单失效<?php  } ?></li>
				<li>预付金额:<strong class="fc_red">￥<?php  echo number_format($order['totalprice'],2)?></strong></li>

				<li>订单总价:<strong class="fc_red">￥<?php  echo number_format($order['amount'],2)?></strong></li>
				<li>付款方式: <?php  if($order['paytype']==1) { ?>余额支付<?php  } else if($order['paytype']==2) { ?>微信支付<?php  } else if($order['paytype']==3) { ?>现金支付<?php  } else { ?>未知方式<?php  } ?><?php  if($order['ispay']==1) { ?><strong class="fc_red">【已付款】</strong><?php  } else { ?>【未支付】<?php  } ?></li>				
			</ul>
            <?php  if($ischef==1) { ?>
            
            
            
            <?php  if($order["serviceendtime"]==0) { ?>
            
            <?php  if($order["servicebetime"]==0) { ?>
            <div class="payment" id="startservice" style="text-align: center;color: #FF8000;font-weight: bold;font-size: 1.5em;"><a href="javascript:;" onclick="javascipt:event.stopPropagation();mystartservice(<?php  echo $order['id'];?>)">开始服务</a></div>
            <?php  } else { ?>
            
            <div class="payment" id="startservice" style="text-align: center;color: #FF8000;font-weight: bold;font-size: 1.5em;"></div>
            <?php  } ?>
            <div class="payment" id="startservice" style="text-align: center;color: #FF8000;font-weight: bold;font-size: 1.5em;"><a href="javascript:;" id="servicepp">服务完成扫码确认</a></div>
            
            <?php  } else { ?>
             <div class="payment" style="text-align: center;font-size: 1.5em;color: #FF8000;">服务完成于<?php  echo date("Y-m-d H:i:s",$order["serviceendtime"]); ?></div>
            
            <?php  } ?>
            
            <?php  } ?>
		</div>
		<div class="item">
			<ul>
                <li>名厨/名店: <a href="mobile.php?act=module&id=<?php  echo $order['shop_id'];?>&name=shopping3&do=wldetailnew&weid=1"><?php  echo $chefname;?></a></li>
				<li>客户姓名: <?php  echo $order['guest_name'];?></li>
				<li>联系手机：<?php  echo $order['tel'];?></li>
				<li>预约时间: <?php  echo $order['time_day'];?></li>
				<li>详细地点: <?php  echo $order['guest_address'];?></li>
                <li>预定人数: <?php  echo $order['time_day'];?></li>
 				<li>订单备注: <?php  echo $order['remark'];?></li>

			</ul>
		</div>

		<div class="item">
			<?php  if(is_array($row)) { foreach($row as $row2) { ?>
			<div class="pro">
				<div class="img">
				<a href="javascript:void(0)" class="dataIn" onclick="showImgDetail('<?php  echo $row2['goodsid'];?>');event.stopPropagation();"><img src="<?php  echo $row2['thumb'];?>"></a></div>
				<dl class="info">
					<dd class="name"><a href="javascript:void(0)" class="dataIn" onclick="showImgDetail('<?php  echo $row2['goodsid'];?>');event.stopPropagation();"><?php  echo $row2['title'];?></a></dd>
					<dd style="width: 30%;">￥<?php  echo number_format($row2['productprice'],2)?></dd>
					<dd style="width: 20%;"><?php  echo $row2['total'];?></dd>
 				</dl>
				<div class="clear"></div>
			</div>
			<?php  } } ?>
			<div class="total_price">订单总额:<span>￥<?php  echo number_format($order['amount'],2)?></span></div>			
		</div>
		<?php  if($status==0&&$order['paytype']!=3) { ?><div class="payment"><a href="<?php  echo $this->createMobileUrl('wlorder', array('d' => payment,'OrderId'=>$order['id']));?>">付款</a></div><?php  } ?>
	</div>
	<?php  } ?>
	
</div>
<link rel="stylesheet" type="text/css" href="<?php echo RES;?>css/wei_canyin.css?2014-02-26-2" media="all" />

<?php  include $this->template(wl_footer, TEMPLATE_INCLUDEPATH);?> 
<script>
            var footer = document.getElementById("footer_menu");
            var evtObj = {
                handleEvent: function(evt){
                    if("A" == evt.target.tagName){
                        evt.target.classList.toggle("on");
                    }
                }
            }
            footer.addEventListener("touchstart", evtObj, false);
            footer.addEventListener("touchend", evtObj, false);
</script>
<script>
    $(document).ready(function(){
        $('#my_menu').click(function(){
           location.href='mobile.php?act=module&name=shopping3&do=wlcart&weid=1';

	    });
        
    });
function mystartservice(id){
 
MDialog.confirm(
                '', '确认开始服务？', null,
                '确定', function() {
                     MLoading.show('加载中');
                    $.ajax({
                        'url': '<?php  echo  $this->createMobileUrl('wlstart',array('id'=>$order['id']))?>',
                        'success': function(db) {
                            MLoading.hide();
							timedCount();
                        }
                    });

                }, null,
                '取消', null, null,
                null, true, true
                );
                    
    
}
var view_const_dish_SPECIAL_PRICE_YES = '2';
var view_const_dish_HOT_YES = '2';
function showImgDetail(thi){
           
            var params = {
            "goodsid":thi,
            "weid":1
            }            
             _doAjax("<?php  echo  $this->createMobileUrl('wldetailajax')?>", "POST", params, function(res) {
                MLoading.hide();
                    
                   if(res.type=="error"||res.type=="ajax"){
                        alert(res.message);    
                   }else{
                       
                popPic(res.thumb,
                    res.title,
                    res.marketprice + '元/'+res.unit,
                    1,
                    res.productprice + '元/'+res.unit,
                    "",
                    res.main,
                    res.content,
                    res.addtion,
                    res.other,
                    res.description
                );
                                        
                   }

                
                            
            
            
            });
        }
function popPic(imgUrl,title,price, isSpecial, specialPrice, people,teast,assess,fliao,xliao,diyliao){
            var _title = title,
                _price = price,
                _people = null;//people,
                _teast = teast,
                _assess = assess;

                var hotHtml = '';
                _tmpHtml = "<div class='content'>"+hotHtml+"<h2>"+_title;



                if (_people) {
                    _tmpHtml += "<span>"+_people+"人点过</span>";
                }
                _tmpHtml += "</h2><img src='"+imgUrl+"' alt='' style='height: 100px;' title=''>";

                 if (isSpecial == view_const_dish_SPECIAL_PRICE_YES) {
                     _tmpHtml += "<h2>价格：<i>"+specialPrice+"</i><del>"+_price+"</del></h2>";
                 } else {
                     _tmpHtml += "<h2>价格：<i>"+_price+"</i></h2>";
                 }
                 
                
                

                _tmpHtml += '</div>';
            MDialog.popupCustom(_tmpHtml,true,true);
        }   
var c=<?php  echo $startt;?>;
var t;
function timedCount()
{
 $("#startservice").html(formatSeconds(c));
 c=c+1;
 t=setTimeout("timedCount()",1000)
}
<?php  if($order["servicebetime"]>0) { ?>
timedCount();
<?php  } ?>

function formatSeconds(value) {
    var theTime = parseInt(value);// 秒
    var theTime1 = 0;// 分
    var theTime2 = 0;// 小时
    // alert(theTime);
    if(theTime > 60) {
        theTime1 = parseInt(theTime/60);  
        theTime = parseInt(theTime%60);  
        // alert(theTime1+"-"+theTime);  
        if(theTime1 > 60) {  
            theTime2 = parseInt(theTime1/60);  
            theTime1 = parseInt(theTime1%60);  
          }  
    }
    var result = ""+parseInt(theTime)+"秒";
    if(theTime1 > 0) {
        result = ""+parseInt(theTime1)+"分"+result;
    }
    if(theTime2 > 0) {
    result = ""+parseInt(theTime2)+"小时"+result;
    }
    return result;
}

wx.ready(function () {
    
document.querySelector('#servicepp').onclick = function () {
    wx.scanQRCode({
      needResult: 1,
      success: function (res) {
        //
        if(res.resultStr.substring(0,5)=="VEGOD"){
            
                    $.ajax({
                        'url': '<?php  echo  $this->createMobileUrl('wlserviceend',array('id'=>$order['id']))?>&code='+res.resultStr,
                        'success': function(db) {
                            MLoading.hide();
                            location.reload();
                        }
                    });
                                
            
        }else{
            alert("不是评价二维码，请进入客户微信中订单详细页面扫描！");    
        }
        
        
      }
    });
  };

});    
    

function startpinjia(thi){
        MLoading.show('加载中');
        var params = {
        }

        _doAjax("<?php  echo  $this->createMobileUrl('wlorderservice',array('id'=>$order['id']))?>", "POST", params, function(res) {
            MLoading.hide();

            if(res.type=="error"){
                alert(res.message);
            }else{

                var _tmpHtml = "<div class='content' style='background-color: white;padding-bottom: 10px'><h2>请选择评分</h2>";
                _tmpHtml += "<center>";
                _tmpHtml += "<select name='sdate' id='sdate'>";
                _tmpHtml += "<option value='0'>请选择</option> ";
               _tmpHtml += "<option value='5'>非常满意</option> ";
               _tmpHtml += "<option value='4'>满意</option> ";
               _tmpHtml += "<option value='3'>一般</option> ";
               _tmpHtml += "<option value='2'>不满意</option> ";
               _tmpHtml += "<option value='1'>极差</option> ";

                _tmpHtml += "</select><br/><span style='color: red;font-size: 10px'></span>";

                _tmpHtml += "<div><button onclick='custompingjia()'>确定评价</button></div>";
                _tmpHtml += "</center>";
                _tmpHtml += "</div>";
                MDialog.popupCustom(_tmpHtml,true,true);


            }

        });


    }
        
</script>
